package com.mavenq.fly.commons.exception;

import com.mavenq.fly.commons.resp.ResponseBuilder;
import com.mavenq.fly.commons.resp.ResponseObj;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ExceptionAdvice {

    @ExceptionHandler(BusinessException.class)
    public ResponseObj businessException(BusinessException exception){
        log.error("businessException ... ", exception);
        return new ResponseBuilder()
                .buildMsg(exception.getMessage())
                .buildCode(exception.getCode()).build();
    }

    @ExceptionHandler(Exception.class)
    public ResponseObj commonException(Exception e){
        log.error("commonException ... ", e);
        return ResponseBuilder.buildFailed();
    }

}
